﻿using System.Collections.Generic;
using System.Linq;

namespace Common
{
    public class CountManager
    {
        static Dictionary<string, Counter> dictionary = new Dictionary<string, Counter>();

        static Dictionary<string, Counter> Dictionary { get { return dictionary; } set { dictionary = value; } }

        public static Counter getCount(string Name)
        {
            if (!Dictionary.ContainsKey(Name))
            {
                Dictionary.Add(Name, new Counter() { Name = Name });
            }
            return Dictionary[Name];
        }
        public static string[] GetNames()
        {
            return dictionary.Select(t => t.Key).ToArray();
        }
        public static void AddFail(string Name)
        {
            if (!Dictionary.ContainsKey(Name))
            {
                Dictionary.Add(Name, new Counter() { Name = Name });
            }
            Dictionary[Name].NG++;
            Dictionary[Name].Total++;
        }
        public static void AddPass(string Name)
        {
            if (!Dictionary.ContainsKey(Name))
            {
                Dictionary.Add(Name, new Counter() { Name = Name });
            }
            Dictionary[Name].Total++;
        }

        public static void Clear()
        {
            foreach(var a in dictionary)
            {
                a.Value.NG = 0;
                a.Value.Total=0;               
            }
        }
    }
}
